﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZWZ.Web.WebAdmin.Update
{
    public partial class BdInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var CurrentUser = Codes.LoginHelper.CurrentUser;
                ctrTxtNickName.Text = CurrentUser.NickName;
                ctrTxtTel.Text = CurrentUser.Tel;
                ctrTxtEmail.Text = CurrentUser.Email;
                ctrTxtBirthday.Text = CurrentUser.Birthday.ToString("yyyy-MM-dd");
                ctrddlGender.SelectedValue = CurrentUser.Gender;
                ctrTxtIntruction.Text = CurrentUser.Introduction;
            }
        }
        protected void ctrbtnSaveInfo_Click(object sender, EventArgs e)
        {
            var MsgBox = new Codes.MessageBox(this);
            try
            {
                var uid = Codes.LoginHelper.CurrentUser.ID;
                var CurrentUser = ZWZ.DBProvider.DB.Ctx.User_Info.Where(i => i.ID == uid).FirstOrDefault();
                CurrentUser.NickName = ctrTxtNickName.TryGetText("昵称");
                CurrentUser.Tel = ctrTxtTel.Text;
                CurrentUser.Birthday = ctrTxtBirthday.TryGetDate("生日");
                CurrentUser.Gender = ctrddlGender.SelectedValue;
                CurrentUser.Introduction = ctrTxtIntruction.Text;
                ZWZ.DBProvider.DB.Ctx.SaveChanges();
                Codes.LoginHelper.ReFrashUserInfo();
                MsgBox.Show("修改成功！").Send();
            }
            catch (Exception exp)
            {
                MsgBox.Show(exp.Message).Send();
            }
        }
    }
}